<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      ul {
        list-style: none;
      }

      .box {
        width: 400px;
        height: 300px;
        border: 1px solid #ccc;
        margin: 100px auto;
      }

      .hd {
        height: 45px;
      }

      .hd span {
        display: inline-block;
        /*将行内元素转换成行内块元素，宽高才起作用*/
        width: 90px;
        background-color: pink;
        line-height: 45px;
        text-align: center;
        cursor: pointer;
      }

      .hd span.current {
        /*交集选择器，标签指定式选择器*/
        background-color: purple;
        /*紫色*/
      }

      .bd li {
        height: 255px;
        background-color: purple;
        display: none;
        /*设置隐藏*/
      }

      .bd li.current {
        display: block;
        /*显示*/
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="hd">
        <span class="current">体育</span>
        <span>娱乐</span>
        <span>新闻</span>
        <span>综合</span>
      </div>
      <div class="bd">
        <ul>
          <li class="current">我是体育模块</li>
          <li>我是娱乐模块</li>
          <li>我是新闻模块</li>
          <li>我是综合模块</li>
        </ul>
      </div>
    </div>
  </body>
  <script>
    const span = document.querySelectorAll("span");
    const lis = document.querySelectorAll("li");
    // 遍历forEach
    span.forEach(function (item, index) {
      item.onmouseover = function () {
        //排他思想
        span.forEach(function (key, index) {
          key.classList.remove("current");
          lis[index].classList.remove("current");
        });
        item.classList.add("current");
        lis[index].classList.add("current");
      };
    });
  </script>
</html>
